<template>
    <div>
        <el-dialog title="新增卖家" :visible.sync="dialogVisible">
            <el-form ref="newSellerFrom" :model="seller" :rules="rules">
                <el-form-item label="昵称" prop="member.nickName">
                    <el-input v-model="seller.member.nickName"></el-input>
                </el-form-item>
                <el-form-item label="余额" prop="member.balance">
                    <el-input type="number" step="0.01"
                              v-model.number="seller.member.balance"></el-input>
                </el-form-item>
                <el-form-item label="注册时间" prop="createDate">
                    <el-date-picker value-format="yyyy-MM-dd" v-model="seller.createDate"></el-date-picker>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="reset">重 置</el-button>
                <el-button type="primary" @click="validateSubmit">提 交</el-button>
                <el-button type="primary" @click="dialogVisible = false">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        data: function () {
            return {
                dialogVisible: false,
                seller: {
                    id: 0,
                    sellerCode: "",
                    member: {
                        balance: 0.00,
                        nickName: ""
                    },
                    createDate: ""
                },
                rules: {
                    member: {
                        balance: [
                            {required: true, message: '请输入剩余金额', trigger: 'blur'},
                            {type: 'number', message: '金额必须为数字值'}
                        ],
                        nickName: [
                            {required: true, message: '请输入昵称', trigger: 'blur'},
                            {min: 0, max: 10, message: '10个字符以内', trigger: 'blur'}
                        ]
                    },
                    createDate:[
                        {required: true, message: '请输入注册日期，注册日期原则上后台生成', trigger: 'change'},
                    ]
                }
            }
        },
        computed: {},
        methods: {
            init:function(){

                this.seller.createDate = new Date().toLocaleDateString().split('/').join('-');
                console.log(this.seller.createDate);
                this.dialogVisible =true;
                this.seller.id='0';
                this.seller.sellerCode='';
            },
            reset:function () {
                this.$refs['newSellerFrom'].resetFields();
            },
            validateSubmit:function () {
                this.$refs['newSellerFrom'].validate((valid)=>{
                    if (!valid){
                        this.$message.warning("输入信息请符合特征格式");
                        return false;
                    }
                    this.$http({
                        method:'put',
                        url:'http://localhost:8899/seller',
                        data:this.seller,
                    }).then(res=>{
                        this.seller = res.data;
                        console.log(res);
                        this.dialogVisible=false;
                        this.$emit('addOver',res.data.sellerCode);
                        this.reset();
                    }).catch(console.log)
                });
            }
        },

        mounted: function () {

        },

        created: function () {

        },
        name: "SellerNew"
    }
</script>

<style scoped>

</style>
